﻿using System.Windows;
using System.Windows.Data;
using SnakeGame.ViewModels;
using SnakeGame.Models;

namespace SnakeGame.Views
{
    /// <summary>
    /// Interaction logic for EditConfigWindow.xaml
    /// </summary>
    public partial class EditConfigWindow : Window
    {
        private EditConfigWindowViewModel _editConfigViewModel;

        public EditConfigWindow()
        {
            InitializeComponent();
        }

        public void Initialize()
        {
            _editConfigViewModel = new EditConfigWindowViewModel();
            _editConfigViewModel.RequestClose += _playerViewModel_RequestClose;

            _editConfigViewModel.Initialize();
            DataContext = _editConfigViewModel;

        }
        void _playerViewModel_RequestClose(object sender, System.EventArgs e)
        {
            Close();
        }

        private void CollectionViewSource_Filter(object sender, FilterEventArgs e)
        {
            Block q = e.Item as Block;
            if (q != null)
            {
                if (ShowUsedCheckbox.IsChecked == true && q.IsUsed == false)
                    e.Accepted = false;
                else
                    e.Accepted = true;
            }
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            CollectionViewSource.GetDefaultView(myDG.ItemsSource).Refresh();
        }

        private void Mouse_Click(object sender, RoutedEventArgs e)
        {
            if (myDG.SelectedItem == null)
                return;

            var q = myDG.SelectedItem as Block;
            _editConfigViewModel.click(q.ID);
        }

    }
}
